Type.registerNamespace('ModWatch');

ModWatch.OnTextBoxChangedModAlertBehavior = function(element) { 
    ModWatch.OnTextBoxChangedModAlertBehavior.initializeBase(this, [element]);

	this._currentValue = '';
	this._previousOnChangeEvent = null;
}

ModWatch.OnTextBoxChangedModAlertBehavior.prototype =
{

	_onChange : function(e)
	{
		if (!ModWatch.OnTextBoxChangedModAlertBehavior.callBaseMethod(this, 'verifyChanges'))
		{
			this.get_element().value = this._currentValue;
			return false;
		}
		else
		{
			this._currentValue = this.get_element().value;

			if (this._previousOnChangeEvent != null)
			{
				return this._previousOnChangeEvent(e);
			}
		}
	},

	initialize : function()
	{
		ModWatch.OnTextBoxChangedModAlertBehavior.callBaseMethod(this, 'initialize');

		var tb = this.get_element();
		var currentChangeEvent = tb.onchange;
		if (typeof currentChangeEvent == 'function')
		{
			this._previousOnChangeEvent = currentChangeEvent;
		}

		this._currentValue = tb.value;

		$addHandlers(tb,
					 { 'change' : this._onChange },
					 this);

		tb.onchange = null;
	},

	dispose : function()
	{
		this.get_element().onchange = this._previousOnChangeEvent;

		$clearHandlers(this.get_element());

		ModWatch.OnTextBoxChangedModAlertBehavior.callBaseMethod(this, 'dispose');
	}

}

ModWatch.OnTextBoxChangedModAlertBehavior.registerClass('ModWatch.OnTextBoxChangedModAlertBehavior', ModWatch.ModAlertBehaviorBase);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
